﻿using System.Web.Mvc;
using ShopB2C.Enums;
using ShopB2C.Helper;
using ShopB2C.ViewModels;

namespace ShopB2C.Controllers.Manager {
    /// <summary>
    /// 新闻
    /// </summary>
    public partial class ConfigController : BaseController {
        [OutputCache(Duration = 0, VaryByParam = "*")]
        public ActionResult News() {
            return View(new NewsConfigViewModel() {
                Title = ConfigHelper.GetValue(ConfigNodeNames.News, "title"),
                ClassifyId = ConfigHelper.GetValue<int>(ConfigNodeNames.News, "classify"),
                ShowNums = ConfigHelper.GetValue<int>(ConfigNodeNames.News, "pagesize"),
                ClassifyList = _classify.GetClassifyByModuleKey("News")
            });
        }

        [HttpPost]
        public ActionResult NewsConfigSave(NewsConfigViewModel ncv) {
            string msg = "保存配置操作成功完成!";
            try {
                ConfigHelper.SetValue<string>(ConfigNodeNames.News, "title", ncv.Title);
                ConfigHelper.SetValue<int>(ConfigNodeNames.News, "classify", ncv.ClassifyId);
                ConfigHelper.SetValue<int>(ConfigNodeNames.News, "pagesize", ncv.ShowNums);
                ConfigHelper.Save();
            }
            catch {
                msg = "发生错误, 保存配置操作失败!";
            }
            return Content(msg, "text/plain");
        }

    }
}
